﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using nr.GLV.Data;
using nr.Reports;

namespace nr.GLV.Windows
{
    public partial class PrintFilesForm : Form
    {
        private nrDataSet data;

        public nrDataSet Data { get { return data; } set { data = value; } }

        public PrintFilesForm()
        {
            data = null;

            InitializeComponent();
        }

        private void PrintFilesForm_Load(object sender, EventArgs e)
        {
            cbFiles.Items.Clear();
            cbFiles.Items.Add("Contribuenti");
            cbFiles.SelectedIndex = 0;
            lblCurrentPrinter.Text = dlgPrinter.PrinterSettings.PrinterName;
        }

        private void btnSetupPrinter_Click(object sender, EventArgs e)
        {
            if (dlgPrinter.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                document.PrinterSettings = dlgPrinter.PrinterSettings;
            }
        }

        private void btnPageSetup_Click(object sender, EventArgs e)
        {
            if (dlgPageSetup.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                document.DefaultPageSettings = dlgPageSetup.PageSettings;
            }
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            ReportCompiler rc = new ReportCompiler();
            rc.Document = document;
            ReportStyle rs = new ReportStyle();
            switch (cbFiles.SelectedIndex)
            {
                case 0:
                    DataView dv = data.Customers.DefaultView;
                    dv.Sort = "FullName ASC";
                    rc.Data = dv;
                    rs.AddColumnStyles(new ReportColumnStyle[]{
                        new ReportColumnStyle("FullName","Contribuente"),
                        new ReportColumnStyle("MainAddress", "Indirizzo"),
                        new ReportColumnStyle("CityName", "Città"),
                        new ReportColumnStyle("Lamps", "L.", "{0:###}", StringAlignment.Far, 10),
                        new ReportColumnStyle("PaymentAmount", "Totale", "{0:C}", StringAlignment.Far, 30)});
                    break;
            }
            rc.Style = rs;
            preview.ShowDialog(this);
        }
    }
}
